package br.com.orion.sga.utils;

import java.awt.Image;
import java.awt.image.BufferedImage;
import java.io.File;
import java.io.IOException;

import javax.imageio.ImageIO;

public class CreateThumbnail {

	private static final int THUMB_HEIGHT = 140, THUMB_WIDTH = 140;
	
	public static void generateThumb(String directory, String filename, String thumbFolder, long idToPhoto) {
		
		try {
			BufferedImage img = new BufferedImage(100, 100, BufferedImage.TYPE_INT_RGB);
			img.createGraphics().drawImage(ImageIO.read(new File(directory + filename)).getScaledInstance(THUMB_HEIGHT, THUMB_WIDTH, Image.SCALE_SMOOTH),0,0,null);
			ImageIO.write(img, "jpg", new File(thumbFolder + idToPhoto + filename));
		} catch (IOException e) {
			e.printStackTrace();
		}
	}
}
